package com.topcycle.tlight;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;

public class BitmapMatrix {
	public final static int PIC_ORI_ALPHA = 180;
	public final static int PIC_ORI_RED = 250;
	public final static int PIC_ORI_GREEN = 220;
	public final static int PIC_ORI_BLUE = 100;
	
	public static Bitmap scaleMatrix(Bitmap bm, int progress, int color) {
		Bitmap bmp = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(),
				Bitmap.Config.ARGB_8888);
		int r = Color.red(color);
		int g = Color.green(color);
		int b = Color.blue(color);
		Canvas canvas = new Canvas(bmp);
		Paint paint = new Paint();
		paint.setAntiAlias(true);
		float hue = (progress + 20) * 1.0f / 80;
		ColorMatrix hueMatrix = new ColorMatrix();
		float[] mArray = {	hue, 		0,    	0,		0,    	(-PIC_ORI_RED+r)*hue,
							0,    	hue, 		0,  	0,    	(-PIC_ORI_GREEN+g)*hue,
							0,    	0,    	hue, 		0,    	(-PIC_ORI_BLUE+b)*hue,
							0,    	0,    	0,   	1,    	0};
		hueMatrix.set(mArray);
		paint.setColorFilter(new ColorMatrixColorFilter(hueMatrix));
		canvas.drawBitmap(bm, 0, 0, paint);
		return bmp;
	}
}